package com.example.administrator.yuejian2.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.administrator.yuejian2.R;
import com.example.administrator.yuejian2.bean.CommentBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class CommentAdapter extends RecyclerView.Adapter {


    private Context context;
    private LayoutInflater layoutInflater;
    private List<CommentBean> list;

    public CommentAdapter(Context context) {
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
    }

    public void commentdata(List<CommentBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = layoutInflater.inflate(R.layout.comment_item, parent, false);
        return new CommentViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        CommentViewHolder viewHolder=(CommentViewHolder)holder;
        CommentBean bean=list.get(position);
        viewHolder.commentTitle.setText(bean.getComment_content());
        viewHolder.commentTime.setText(bean.getComment_time());
    }

    @Override
    public int getItemCount() {
        if (list == null) {
            return 0;
        } else {
            return list.size();
        }
    }

    class CommentViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.comment_title)
        TextView commentTitle;
        @BindView(R.id.comment_time)
        TextView commentTime;
        public CommentViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
